/** 
 * 登录权限相关
*/

import { defineStore } from "pinia";

export const useAuthStore = defineStore('auth', {
    state: () => ({
        isAuth: false,
        token: localStorage.getItem('token') || ''
    }),
    actions: {
        setAuth(token) {
            this.token = token;
            this.isAuth = true;
            localStorage.setItem('token', token)
        },
        logout() {
            this.token = '';
            this.isAuth = false;
            localStorage.removeItem('token');  // 移除 token
        }
    },
    persist: {
        enable: true,
        strategise: [
            {
                storage: localStorage, // 持久化到本地存储
                paths: ['isAuth', 'token'] // 指定需要持久化的字段
            }
        ]
    }
})